﻿using System;
using System.Windows.Forms;
using System.Drawing;
using Cartography.Desktop;

namespace PointOfInterest.Desktop
{
    public class Point : PictureBox
    {
        int pixelX;
        int pixelY;
        int zoom; //
        string address,name;
        LatLon coordinates;
        Boolean clic;

        // Booleano para determinar si el punto está resaltado o no
        bool resalted = false;

        public Point(LatLon coordinates, string name, string address, Bitmap icon)
        {
            this.name = name;
            this.address= address;
            this.coordinates= coordinates;
            this.pixelX = 0;
            this.pixelY = 0;
            this.zoom = -1;
            this.Click +=new EventHandler(this.clickHandler);
            //this.MouseHover+=new EventHandler(this.clickHandler);
            //this.MouseLeave+= new EventHandler(this.clickHandlerOut);
            this.Image = icon;
            this.Size = icon.Size;
            this.BackColor = Color.Transparent;
            this.clic = false;
        }
        private void clickHandler(object sender, EventArgs e)
        {
            this.generarMensage();
            this.clic = !this.clic;
            return;

        }
        public void estaSeleccionado() 
        {
            if (this.clic) this.generarMensage();
        }
        private void generarMensage() 
        {
            // Pedimos el Parent
            //            ((PictureBox)sender).Parent
            int locationX = this.Location.X + this.Width;
            int locationY = this.Location.Y + this.Height;
            this.Parent.Controls.RemoveByKey("VentanaInfo");
            Label info = new Label();
            string infoString = this.Name + ":\n" + this.Address;
            Font stringFont = new Font("Arial", 12);
            Size textSize = TextRenderer.MeasureText(infoString, stringFont);
            info.Font = stringFont;
            info.Text = infoString;
            info.Name = "VentanaInfo";
            info.Location = new System.Drawing.Point(0, 0);
            info.ForeColor = Color.Black;
            info.BackColor = Color.White;
            info.Visible = true;
            info.BorderStyle = BorderStyle.FixedSingle;
            info.Size = info.PreferredSize;
            if (locationX + info.Size.Width > this.Parent.Width)
                locationX -= (this.Width + info.Size.Width);
            if (locationY + info.Size.Height > this.Parent.Height)
                locationY -= (this.Height + info.Size.Height);

            info.Location = new System.Drawing.Point(locationX, locationY);
            this.Parent.Controls.Add(info);
            info.BringToFront();
        }
        public string Address
        {
            get { return this.address; }
            set { this.address = value; }
        }
        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public int actualZoom
        {
            get { return this.zoom; }
            set { this.zoom = value; }
        }

        public int actualPixelX
        {
            get { return this.pixelX; }
            set { this.pixelX = value; }
        }
        public int actualPixelY
        {
            get { return this.pixelY; }
            set { this.pixelY = value; }
        }

        public LatLon Coordenadas
        {
            get { return this.coordinates; }
            set { this.coordinates = value; }
        }
        public bool Resaltado
        {
            get { return this.resalted; }
            set { this.resalted = value; }
        }
    }
}
